CMAKE_MINIMUM_REQUIRED(VERSION 3.1)
PROJECT(Solver)

#1. 设置语言版本
set(CMAKE_CXX_STANDARD 17)            #支持c++17
set(CMAKE_CXX_STANDARD_REQUIRED True) #不支持c++17则报错

#2. 设置编译类型
set(CMAKE_BUILD_TYPE "Release")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
    message(STATUS "设置编译类型为:Debug")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -Wextra -O0 -DDEBUG")
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
    message(STATUS "设置编译类型为:Release")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -Wall -Wextra -DNDEBUG")
else()
    message(FATAL_ERROR "不支持此编译类型.")
endif()

#3.
include_directories(${CMAKE_SOURCE_DIR}/core/include)
include_directories(${CMAKE_SOURCE_DIR}/solver/include)
include_directories(${CMAKE_SOURCE_DIR}/testFun/common/include)
include_directories(${CMAKE_SOURCE_DIR}/testFun/NIST/include)
include_directories(${CMAKE_SOURCE_DIR}/testFun/CEC2017/include)
file(GLOB coreCPP ${CMAKE_SOURCE_DIR}/core/src/*.cpp)
file(GLOB solverCPP ${CMAKE_SOURCE_DIR}/solver/src/*.cpp)
file(GLOB NISTCPP ${CMAKE_SOURCE_DIR}/testFun/NIST/src/*.cpp)
file(GLOB CEC2017CPP ${CMAKE_SOURCE_DIR}/testFun/CEC2017/src/*.cpp)
file(GLOB funCPP ${CMAKE_SOURCE_DIR}/testFun/common/src/*.cpp)
set(srcCore ${coreCPP} ${solverCPP} ${funCPP} ${NISTCPP} ${CEC2017CPP})

#4.
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib)
add_library(core STATIC ${srcCore})

#5. 
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
add_executable(solveEqu ${CMAKE_SOURCE_DIR}/example/exampleSolveEqu.cpp)
TARGET_LINK_LIBRARIES(solveEqu core pthread)

add_executable(solveFit ${CMAKE_SOURCE_DIR}/example/exampleSolveFit.cpp)
TARGET_LINK_LIBRARIES(solveFit core pthread)

add_executable(testSolver ${CMAKE_SOURCE_DIR}/example/exampleTestSolver.cpp)
TARGET_LINK_LIBRARIES(testSolver core pthread)

add_executable(unitTest ${CMAKE_SOURCE_DIR}/example/unitTest.cpp)
TARGET_LINK_LIBRARIES(unitTest core pthread)